# 定义类
## object类 = 基类
class Player(object):
    count = 0
    def __init__(self):
        Player.count += 1
        print("构造函数被调用")

# 类的实例化
tom = Player()
jack = Player()
jack.name = "jack"
print(jack.name)

class Player2(object):
    def __init__(self,name,age):
        self.name = name
        self.age = age

tim = Player2('tim',18)
print(tim.name,tim.age)

# 以字典的形式打印对象的所有属性
print(tim.__dict__)

# 关于武器的类
## 武器名 / 武器攻击力 / 武器品阶
class Weapon(object):
    max_damage = 1000
    ranks = ['青铜','白银','黄金','钻石','王者']
    def __init__(self,name,damage,rank):
        self.name = name
        if damage > Weapon.max_damage:
            raise Exception('超出最大伤害限制!')
        else:
            self.damage = damage
        if rank not in Weapon.ranks:
            raise Exception("武器品阶设置错误")
        else:
            self.rank = rank


try:
    gun = Weapon("大炮",1000,'青铜')
    print(gun.__dict__)
except Exception as e:
    print(e)

print(Player.count)